TailsConfig.registerFormat({
  name: 'hfeed',
  topNodeClass: 'hentry',

  simpleValueClasses: ["entry-title", "entry-content", "entry-summary"],

  dateValueClasses: ["updated", "published"],

  genericLabelAttributes: ["entry-title"],
  genericURLAttributes: ["bookmark"],

  customBindings: {
    author: function(node, object) {
      object.author_hcard = TailsConfig.getFormat("hcard").parseObject(node);
      return true;
    }
  },
  objectMethods: {
    getTagString: function() {
      if (!this.tags) return null;
      var names = [];
      for (var i=0; i<this.tags.length; i++) names.push(this.tags[i].name);
      return names.join(", ");
    }
  },

  _getDescription: function(object) {
    if (object.updated_date)
      return FormatBase.prettyDate(object.updated_date);
    if (object.tags)
      return TailsNS.getMessage("hfeed_tags_label", [object.getTagString()]);

    var content = object['entry-content'];
    if (content) {
      if (content.length > 72) {
        var pos = -1;
        for (var i=72; i>=0; i--) {
          if (content[i] == ' ') {
            pos = i;
            break;
          }
        }
        if (pos < 0) pos = 72;
        content = content.substring(0, pos);
        content += "...";
      }
      return content;
    }
  },
  _checkNode: function(node, object) {
    if (node.tagName.toLowerCase() == "a") {
      var rel = node.getAttribute("rel");
      if (rel == "bookmark")
        object.bookmark = FormatBase.toURL(node);
      else if (rel == "tag") {
        var tag = {name: FormatBase.toText(node), url: FormatBase.toURL(node)};
        if (!object.tags) object.tags = [];
        object.tags.push(tag);
      }
    }
  },

  end: null
});
